package com.video_study.service.serviceImpl;

import com.video_study.dao.UserApproveMapper;
import com.video_study.pojo.UserApprove;
import com.video_study.result.ExceptionMsg;
import com.video_study.result.ResponseData;
import com.video_study.service.UserApproveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.UUID;

@Service
public class UserApproveServiceImpl implements UserApproveService {
    @Autowired
    UserApproveMapper userApproveMapper;
    @Override
    @Transactional
    public ResponseData insert(UserApprove userApprove) {
        try{
            userApprove.setId(UUID.randomUUID().toString());
            userApproveMapper.insert(userApprove);
            System.out.println(userApprove);
            return new ResponseData(ExceptionMsg.SUCCESS);
        }catch(Exception e){
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return new ResponseData("000407","未知异常");

        }

    }

    @Override
    @Transactional
    public ResponseData delete(UserApprove userApprove) {
        try{
            Integer result = userApproveMapper.delete(userApprove);
            return new ResponseData(ExceptionMsg.SUCCESS);
        }catch(Exception e){
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return new ResponseData("000407","未知异常");

        }
    }
}
